package com.zut.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zut.pojo.Parents;
import com.zut.service.ParentsService;
import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;


@Controller
public class RegisterController {
    @Resource
    private ParentsService parentsService;

    //注册功能
    @RequestMapping("/register")
    public String register(String name, String tel,String password,String repassword, Model model){

        QueryWrapper<Parents> wrapper=new QueryWrapper<>();
        wrapper.eq("parname",name);
        Parents parent=parentsService.getOne(wrapper);
        if(parent==null){
            if (password.equals(repassword)){
                Parents parents=new Parents();
                parents.setParname(name);
                parents.setParpwd(password);
                parents.setParphone(tel);
                parentsService.save(parents);
                return "redirect:/log-in";
            }else {
                model.addAttribute("msg","两次密码输入不一样，请重新注册");
                return "registration";
            }

        }else {
            model.addAttribute("msg","该用户名已经存在，请重新注册");
            return "registration";
        }
    }

}
